////////////////////////////////////////////////////////////////////////////////
//      
//      Kingsoft File for shp routines file
//      
//      File      : she_style.h
//      Comment   : simple html parser style class
//					
//      Create at : 2012-12-26 20:27:50
//      Create by : chenguicheng
//      
////////////////////////////////////////////////////////////////////////////////

#pragma once

#define SHP_STYLE_ITEM_KEY				TEXT("style")

#define SHP_NO_ALPHA			0xFF

class shp_style : public IShpParse
{
public:

	shp_style()
		:m_clr_bg(CLR_INVALID),
		m_clr_border(CLR_INVALID),
		m_clr_text(0),
		m_clr_hover(CLR_INVALID),
		m_clr_down(CLR_INVALID),
		m_clr_disable(CLR_INVALID),

		m_w_font(0),
		m_w_font_hover(0),
		m_w_font_down(0),

		m_i_alpha(SHP_NO_ALPHA),
		m_u_fmt(0),
		m_i_cursor(0),
		m_x_margin(0),
		m_y_margin(0)
	{

	};

	~shp_style()
	{

	};

	//set_attribute( p, m )
	BEGIN_KEY_MAP()

		ADD_FONT_KEY( L"font",			m_w_font )
		ADD_FONT_KEY( L"font_hover",	m_w_font_hover )
		ADD_FONT_KEY( L"font_down",		m_w_font_down )

		ADD_CLR_KEY( L"clr_border",		m_clr_border )
		ADD_CLR_KEY( L"clr_bg",			m_clr_bg )
		ADD_CLR_KEY( L"clr_text",		m_clr_text )
		ADD_CLR_KEY( L"clr_hover",		m_clr_hover )
		ADD_CLR_KEY( L"clr_down",		m_clr_down )
		ADD_CLR_KEY( L"clr_disable",	m_clr_disable )

		ADD_HEX_KEY( L"fmt",			m_u_fmt )

		ADD_INT_KEY( L"alpha",			m_i_alpha )
		ADD_INT_KEY( L"x_margin",		m_x_margin )
		ADD_INT_KEY( L"y_margin",		m_y_margin )
		ADD_INT_KEY( L"cursor",			m_i_cursor )
		ADD_STR_KEY( L"name",			m_str_name )

	END_KEY_MAP()

	void get_state_style( shpclr& clr_text, WORD& w_font, int i_state )
	{
		if( i_state == item_state_normal )
		{
			if( clr_text == CLR_INVALID )
				clr_text = m_clr_text;

			if( w_font == 0 )
				w_font = m_w_font;
		}
		else if( i_state == item_state_hover )
		{
			if( m_clr_hover != CLR_INVALID )
				clr_text = m_clr_hover;
			else
				get_state_style( clr_text, w_font, item_state_normal );

			if( m_w_font_hover != 0 )
				w_font = m_w_font_hover;
			else
				get_state_style( clr_text, w_font, item_state_normal );
		}
		else if( i_state == item_state_down )
		{
			if( m_clr_down != CLR_INVALID )
				clr_text = m_clr_down;
			else
				get_state_style( clr_text, w_font, item_state_hover );

			if( m_w_font_down != 0 )
				w_font = m_w_font_down;
			else
				get_state_style( clr_text, w_font, item_state_hover );
		}
		else if( i_state == item_state_disable )
		{
			if( m_clr_disable != CLR_INVALID )
				clr_text = m_clr_disable;
			else
				get_state_style( clr_text, w_font, item_state_normal );

			if( w_font == 0 )
				w_font = m_w_font;
			else
				get_state_style( clr_text, w_font, item_state_normal );
		}
	}

public:

	WORD		m_w_font;
	WORD		m_w_font_hover;
	WORD		m_w_font_down;

	shpclr		m_clr_border;
	shpclr		m_clr_bg;
	shpclr		m_clr_text;
	shpclr		m_clr_hover;
	shpclr		m_clr_down;
	shpclr		m_clr_disable;
	
	UINT		m_u_fmt;
	int			m_i_alpha;
	int			m_x_margin;
	int			m_y_margin;
	int			m_i_cursor;

	shpstr		m_str_name;
	
};


